﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class wjTrade : System.Web.UI.Page
{
    public string Title, aa, p_UserID;
    public string Keywords;
    public string Description;
    string strSQL, SQL;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            WebSiteInfo();
            list_bind();
        }
    }
    public void WebSiteInfo()
    {
        DataTable dt = Class1.ExecSel("select WS_Title,WS_keywords,WS_description from Site_Config");
        this.Title = Convert.ToString(dt.Rows[0]["WS_Title"]);
        this.Keywords = Convert.ToString(dt.Rows[0]["WS_keywords"]);
        this.Description = Convert.ToString(dt.Rows[0]["WS_description"]);
    }
   

    private void list_bind()
    {
       
        SqlConnection conn = Class1.DBconnection();
       //SQL = "select * from  wj_User w Left join Product p on w.wj_ID=P.p_UserID";

        //SQL = "select * from  wj_User w Left join Product p on w.wj_ID=P.p_UserID where wj_CompanyName != null ";

        SQL = "select * from  wj_User where wj_true=1 order by wj_ID desc";

        SqlDataAdapter da = new SqlDataAdapter(SQL, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable dt = ds.Tables[0];

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            //p_UserID = ds.Tables[0].Rows[i]["wj_ID"].ToString();

            if (ds.Tables[0].Rows[i]["wj_CompanyName"].ToString().Length > 50)
            {
                ds.Tables[0].Rows[i]["wj_CompanyName"] = ds.Tables[0].Rows[i]["wj_CompanyName"].ToString().Substring(0, 50) + "...";
            }
            if (ds.Tables[0].Rows[i]["wj_Content"].ToString().Length > 100)
            {
                string str = ds.Tables[0].Rows[i]["wj_Content"].ToString();
                str = str.Replace("<BR>", "");
                str = str.Replace("&nbsp;", "");

                ds.Tables[0].Rows[i]["wj_Content"] = str.Substring(0, 100) + "...";
            }

            if (ds.Tables[0].Rows[i]["wj_LogoImg"].ToString() != "" && ds.Tables[0].Rows[i]["wj_LogoImg"].ToString() != null)
            {
                ds.Tables[0].Rows[i]["wj_LogoImg"] = "<a href='Company/index-" + ds.Tables[0].Rows[i]["wj_ID"].ToString().Trim() + ".html' target=_blank><img src=" + ds.Tables[0].Rows[i]["wj_LogoImg"].ToString().Trim() + " border=0 width=100 height=101/></a>";
            }
            else
            {
                ds.Tables[0].Rows[i]["wj_LogoImg"] = "<img src=img/no.gif>";
            }
        }


        if (dt.Rows.Count > 0)
        {
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = ds.Tables[0].DefaultView;

            pds.AllowPaging = true;
            pds.PageSize = 10;
            int curPage;

            if (Request.QueryString["page"] != null)
            {
                curPage = Convert.ToInt32(Request.QueryString["page"]);
            }
            else
            {
                curPage = 1;
            }

            pds.CurrentPageIndex = curPage - 1;
            this.Repeater1.DataSource = pds;
            this.Repeater1.DataBind();
            this.Label1.Text += "<a>共有<font color=red><b>" + ds.Tables[0].Rows.Count.ToString() + "</b></font>条记录</a>&nbsp;";
            this.Label1.Text += "<a>每页显示<font color=red><b>" + pds.PageSize + "</b></font>条</a>&nbsp;";
            this.Label1.Text += "<a>共<font color=red><b>" + pds.PageCount.ToString() + "</b></font>页</a>&nbsp;";
            this.Label1.Text += "<a>当前第<font color=red><b>" + curPage.ToString() + "</b></font>页</a>&nbsp;&nbsp;";
            if (curPage == 1)
            {
                this.Label1.Text += "<a>首页</a>&nbsp;";
                this.Label1.Text += "<a>上一页</a>&nbsp;";
            }
            else
            {
                this.Label1.Text += "<a href='wjCompany_1.html'>首页</a>&nbsp;";
                this.Label1.Text += "<a href='wjCompany_" + (curPage - 1).ToString() + ".html'>上一页</a>&nbsp;&nbsp;&nbsp;";
            }
            if (curPage == pds.PageCount)
            {
                this.Label1.Text += "<a>下一页</a>&nbsp;";
                this.Label1.Text += "<a>尾页</a>&nbsp;";
            }
            else
            {
                this.Label1.Text += "<a href='wjCompany_" + (curPage + 1).ToString() + ".html'>下一页</a>&nbsp;&nbsp;&nbsp;";
                this.Label1.Text += "<a href='wjCompany_" + pds.PageCount.ToString() + ".html'>尾页</a>&nbsp;";
            }

            string HtmlSelectString = "<select onchange=\"javascript:window.location=this.value\">";
            for (int i = 1; i <= pds.PageCount; i++)
            {
                if (i == curPage)
                {
                    HtmlSelectString += "<option value=wjCompany_" + i + ".html selected>第" + i + "页</option>";
                }
                else
                {
                    HtmlSelectString += "<option value=wjCompany_" + i + ".html>第" + i + "页</option>";
                }
            }
            HtmlSelectString += "</select>";

            this.Label1.Text += "<a>" + HtmlSelectString + "</a>";
        }
        else
        {
            this.Label1.Text = "当前没有记录";
        }
        ds.Dispose();
        da.Dispose();
        conn.Close();
        conn.Dispose();
    }

}
